package com.gitee.swsk33.dborder.dao;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gitee.swsk33.dbentity.dataobject.Order;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrderDAO extends BaseMapper<Order> {

	/**
	 * 添加关联记录
	 *
	 * @param orderId   订单id
	 * @param productId 商品id
	 * @return 增加记录条数
	 */
	@Insert("insert into `order_product` values (#{orderId}, #{productId})")
	@DS("bridge")
	int insertRecord(int orderId, int productId);

	/**
	 * 根据订单id查询其对应的所有商品id列表
	 *
	 * @param orderId 订单id
	 * @return 商品id列表
	 */
	@Select("select `product_id` from `order_product` where `order_id` = #{orderId}")
	@DS("bridge")
	List<Integer> selectProductIds(int orderId);

	/**
	 * 删除和某个订单关联的商品id记录
	 *
	 * @param orderId 订单id
	 * @return 删除记录数
	 */
	@Delete("delete from `order_product` where `order_id` = #{orderId}")
	@DS("bridge")
	int deleteProductIds(int orderId);

}